<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Common\Repositories\System;

use App\Common\Dao\System\CustomerRolesDao;
use App\Common\Repositories\BaseRepository;

/**
 * Class BaseRepository.
 * @mixin CustomerRolesRepository
 */
class CustomerRolesRepository extends BaseRepository
{
    protected bool $checkPassword = true;

    public function __construct(CustomerRolesDao $dao)
    {
        $this->dao = $dao;
    }

    public function getList(array $where = []){
        $query = $this->dao->search($where);
        $data = $query->with(['permissions'])->get();
        $list = $this->toTree($data, 0, 'parent_id', 'children');
        return $list;
    }

    public function getfirst(array $where = []){
        $query = $this->dao->search($where);
        $data = $query->with(['permissions'])->first();
        $list = $this->toTree($data->permissions, 0, 'parent_id', 'children');
        unset($data->permissions);
        $data->permissions = $list;
        return $data;
    }

}
